#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<deque>
#include<stack>
using namespace std;

class Solution {
public:
    vector<int> nextGreaterElements(vector<int>& nums) {
        //使用单调栈
        stack<int> S;
        
        int size = nums.size();
        vector<int> result(size,-1);
        for(int i = 0;i<2*size;++i){
            if(S.empty()){
                S.push(i%size);
            }
            else{
                if(nums[i%size]<=nums[S.top()]){
                    S.push(i%size);
                }
                else{
                    while(!S.empty()&&nums[S.top()]<nums[i%size]){
                        result[S.top()]=nums[i%size];
                        S.pop();
                    }
                    S.push(i%size);
                }
            }
        }
        return result;
    }
};


int main(){
    Solution S;
    vector<int> nums = {1,2,1};
    vector<int> result = S.nextGreaterElements(nums);
    return 0;
}